package de.hwrBerlin.dataMining.view.vImage.figures;

import org.dom4j.Document;
import org.dom4j.Element;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

public class Line extends Figure {

    public int x1, x2, y1, y2;
    
    public Line(int pX1, int pY1, int pX2, int pY2) {
        x1 = pX1;
        y1 = pY1;
        x2 = pX2;
        y2 = pY2;
    }

    public void paintImage(GC pGc){
        setValuesToGc(pGc);
        pGc.drawLine(x1, y1, x2, y2);
    }

    @Override
    public Rectangle getBounds() {
        int width = Math.max(x1, x2) > 0 ? Math.max(x1, x2) : 0;
        int height = Math.max(y1, y2) > 0 ? Math.max(y1, y2) : 0;
        
        return new Rectangle(0, 0, width, height);
    }

    @Override
    public void paintSVG(Document pDocument) {
        Element root = pDocument.getRootElement();
        
        Element line = root.addElement("line");
        
        setValuesToSVGElement(line);
        
        line.addAttribute("x1", ""+x1);
        line.addAttribute("y1", ""+y1);
        line.addAttribute("x2", ""+x2);
        line.addAttribute("y2", ""+y2);
    }
    
}
